package com.dn.designpatterns.bridge;

import com.google.gson.internal.bind.util.ISO8601Utils;

/**
 * @program: designpatterns
 * @description: 桥接模式
 * @author: DN
 * @create: 2021-04-10 15:30
 **/
public class Bridge {
    public static void main(String[] args) {
        Implementor implementor = new ConcreteImplementorA();
        Abstraction abs = new RefinedAbstraction(implementor);
        abs.OperationImpl();
    }
}

interface Implementor {
    void OperationImpl();
}

class ConcreteImplementorA implements Implementor {
    @Override
    public void OperationImpl() {
        System.out.println("ConcreteImplementorA->");
    }
}

class ConcreteImplementorB implements Implementor {
    @Override
    public void OperationImpl() {
        System.out.println("ConcreteImplementorB->");
    }
}

// 抽象化角色
abstract class Abstraction {
    Implementor implementor;

    Abstraction(Implementor implementor){
        this.implementor = implementor;
    }

    public abstract void OperationImpl();
}

// 扩展抽象化角色
class RefinedAbstraction extends Abstraction {
    protected RefinedAbstraction(Implementor implementor) {
        super(implementor);
    }
    @Override
    public void OperationImpl() {
        System.out.println("扩展抽象化角色被访问");
        implementor.OperationImpl();
    }
}